package com.simple.framework.web.service.impl;

import com.github.zuihou.base.R;
import com.simple.business.domain.enumeration.ThirdAuthenticationEnum;
import com.simple.business.domain.vo.login.UserLoginSuccessVO;
import com.simple.framework.security.custom.ThirdAuthenticationToken;
import com.simple.framework.web.service.ProviderAuthenticationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class DirectLoginAuthenticationServiceImpl implements ProviderAuthenticationService {
    @Override
    public List<ThirdAuthenticationEnum> supportsProvider() {
        return Collections.singletonList(ThirdAuthenticationEnum.DIRECT);
    }

    @Override
    public R<UserLoginSuccessVO> authenticate(ThirdAuthenticationToken authenticationToken, HttpServletRequest request) {
        if (authenticationToken.getDetails() instanceof UserLoginSuccessVO) {
            return R.success((UserLoginSuccessVO) authenticationToken.getDetails());
        }
        return R.fail("无效的登录");
    }
}
